package Renderer.HTMLDrawer;
import Renderer.HTMLRenderer;
import Tree.Node;

/**
 *
 * @author ns214
 */
public class List extends Drawer
{
    private static int index = 1;
    private static boolean isOrdered = false;

    /**
     * The Constuctor for this class, which calls the Drawer superclass and 
     * passes the node and renderer to it.
     * @param node The Node to be passed to Drawer.
     * @param renderer The Renderer to be passed to Drawer.
     */
    public List(Node node, HTMLRenderer renderer)
    {
        super(node, renderer);
    }

    /**
     * The overwritten draw method. Processes the current list tag. If it is a
     * list item, the bullet or number of the list item will be sent to the renderer
     * as text to be drawn before the text of the list item. Otherwise, if this
     * is a list definition, an indent is created.
     */
    public void draw()
    {
        newLine();
        String token = node.getToken().toLowerCase();
        if(token.equals("li"))
        {
            if(isOrdered)
            {
                renderer.drawText(index+". ");
                index++;
            }
            else
            {
                renderer.drawText("• ");
            }
        }
        else
        {
            renderer.increaseIndent();
            isOrdered = ((HTMLParser.HTMLTag.List)node).isOrdered();
        }
    }
    
    /**
     * The overwritten postProcess method. This will, unless the tag was a list
     * item (in which case nothing happens) reset the numbering for another list
     * along with decrementing the indent made in draw().
     */
    public void postProcess()
    {
        String token = node.getToken().toLowerCase();
        if(token.equals("ol") || token.equals("ul"))
        {
            renderer.descreaseIndent();
            newLine();
            index = 1;
            isOrdered = false;
        }
    }
}
